package com.gdth.utils;

import java.util.Random;

import com.alibaba.fastjson.JSONObject;
import com.gdth.coder.encrypt.Encryption;

public class webViewUtils {
	
	public static String NewUrl(String url) {
			if(url.contains("attestation=")) {
				return url;
			}else {
				JSONObject object = new JSONObject();
	    		 int param =  new Random(1).nextInt(1000000);
	    		 JSONObject object1 = new JSONObject();
	    		 object1.put("param1", param);
	    		 object1.put("param2", System.currentTimeMillis());
	    		 String param2 = "";
	    		 try {
	    			 param2 = Encryption.encrypt(object1.toString());
	    		} catch (Exception e) {
	    			// TODO Auto-generated catch block
	    			e.printStackTrace();
	    		}
	    		 object.put("param1",param);
	    		 object.put("param2", param2);
	    		// String url = request.getUrl().toString();
	    		 String newUrl = "";
	    		 if(url.contains("?")) {
	    			  try {
	    				newUrl = url + "&attestation=" + Encryption.encrypt(object.toString());
	    			} catch (Exception e) {
	    				// TODO Auto-generated catch block
	    				e.printStackTrace();
	    			} 
	    		 }else {
	    			  try {
	    				newUrl = url + "?attestation=" + Encryption.encrypt(object.toString());
	    			} catch (Exception e) {
	    				// TODO Auto-generated catch block
	    				e.printStackTrace();
	    			}
	    		 }
	    		 return newUrl;
			}
	}

	
	public static String getHeadParam() {
		JSONObject object = new JSONObject();
		 int param =  new Random(1).nextInt(1000000);
		 JSONObject object1 = new JSONObject();
		 object1.put("param1", param);
		 object1.put("param2", System.currentTimeMillis());
		 String param2 = "";
		 try {
			 param2 = Encryption.encrypt(object1.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 object.put("param1",param);
		 object.put("param2", param2);
		 try {
			return Encryption.encrypt(object.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
	}
}
